package cjakma.study.portfolio.common.validation.constraints.impl;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import cjakma.study.portfolio.common.validation.constraints.CodeStringValue;

/**
 * 문자열 코드의 validator.
 * @author 서성수
 */
public class CodeStringValueValidator implements ConstraintValidator<CodeStringValue, String> {

	private String[] codeValues;

	//@Override
	public void initialize(CodeStringValue constraint) {
		this.codeValues = constraint.value();
	}

	//@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if (value == null || value.isEmpty())
			return true;
		for (String codeValue : codeValues) {
			if (codeValue.equals(value))
				return true;
		}
		return false;
	}

}
